<%@ tag language="java" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<%@ attribute name="id" type="java.lang.String" required="true" description="编号"%>
<%@ attribute name="name" type="java.lang.String" required="true" description="输入框名称"%>
<%@ attribute name="value" type="java.lang.String" required="true" description="输入框值"%>
<%@ attribute name="labelName" type="java.lang.String" required="true" description="输入框名称"%>
<%@ attribute name="labelValue" type="java.lang.String" required="true" description="输入框值"%>
<%@ attribute name="title" type="java.lang.String" required="true" description="选择框标题"%>
<%@ attribute name="url" type="java.lang.String" required="true" description="树结构数据地址"%>
<%@ attribute name="cssClass" type="java.lang.String" required="false" description="css样式"%>
<%@ attribute name="cssStyle" type="java.lang.String" required="false" description="css样式"%>
	<input id="${id}Id" name="${name}.id" class="${cssClass}" type="hidden" value="${value}"/>
	<input id="${id}Name" name="${labelName}" readonly="readonly" type="text" value="${labelValue}" maxlength="50"
		class="${cssClass}" style="${cssStyle}"/>
		<a id="${id}Button" type="0" href="javascript:" class="btn btn-primary">${title}</a>&nbsp;&nbsp;
<script type="text/javascript">
	var selectJsonData = null;
	function onSearchCustomer(){
		var searchName = $("#searchName", parent.document).val();
		var type = $('input[type="radio"][name="searchType"]:checked', parent.document).val();
		var html = '';
	 	for(var i = 0, k = selectJsonData.length; i < k; i++) {
       		var node = selectJsonData[i];
       		if(type == "0") {
       			if(node.name.indexOf(searchName) > -1) {
           			html += '<li id='+node.id+'><a>'+ node.name +'</a></li>';
           		}
       		} else if(type == "1") {
       			if(node.nickName.indexOf(searchName) > -1) {
           			html += '<li id='+node.id+'><a>'+ node.name +'</a></li>';
           		}
       		} else {
       			if(node.mobile.indexOf(searchName) > -1) {
           			html += '<li id='+node.id+'><a>'+ node.name +'</a></li>';
           		}
       		}
       	}
	 	$("#productSelectList ul", parent.document).html(html);
	}
	$("#${id}Button").click(function(){
		jQuery.ajax({  
	          type : 'GET',  
	          url : "${url}",  
	          success : function(data) {
	        	 var jsonData = $.parseJSON(data); 
	        	 selectJsonData = jsonData;
	        	 var html = '<div id="productSelectList" style="margin-left:30px;height:400px;overflow:auto;">'+
	        	 '<div style="margin-top:10px;"><input type="radio" name="searchType" value="0" checked/>姓名'+
	     		 '<input type="radio" name="searchType" value="1"/>备注名'+
	     		 '<input type="radio" name="searchType" value="2"/>手机号码'+
	        	 '</div><div style="margin-top:10px;"><input type="text" name="searchName" id="searchName">'+
	 		     '</div><ul>';
	        	 for(var i = 0, k = jsonData.length; i < k; i++) {
	        		var node = jsonData[i];
	        		html += '<li><a id='+node.id+'>'+ node.name +'</a></li>';
	        	 }
	        	 html += "</ul></div>";
	             top.$.jBox(html, {title: "${title}", width:300});
	             $('#searchName', parent.document).keyup(onSearchCustomer);
	             $('#productSelectList ul', parent.document).delegate("li a", "click", function(){
	            	var item =  $(this);
	 				$("#${id}Id").val(item.attr("id"));
					$("#${id}Name").val(item.html());
	 				top.$.jBox.close();
	             });
	          },  
	          error : function(data) {  
	        	  top.$.jBox.tip("查询失败");
	          }  
	    }); 
	});
</script>